<?php
/*
PWision extension: Newspaper http://pw-newspaper.googlecode.com/
Copyright (C) 2010--12 Becheru Petru-Ioan

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
include_once('inc/PProcessor.inc');
include_once('inc/BBCode.inc');
include_once("inc/PFormSection.inc");
include_once('inc/PRedirectSection.inc');
include_once("pw-newspaper.inc");
/** 	The HTML2BBCode class is designed to model the section that allows a user to translate text from HTML to pw-newspaper BBCode. This section is used with very good results to import from HTML files created by openoffice writer.
	*	\latexonly \label{PWision:Extensions:Newspaper:HTML2BBCode} \index{HTML2BBCode} \index{BBCode}\endlatexonly
	*	\brief HTML to BBCode.
	*	\version 2.1.2
	*/
class HTML2BBCode extends PBasicFormSection
	{
	protected function preprocessParam($param_name)
		{
		$_REQUEST[$param_name]=
			str_replace(
				array(
					'\"',
					"\t"/*,
					"\n",
					"\xA","\xD"*/
					),
				array(
					'"',
					' '/*,
					' ',
					'',''*/
					),
				$_REQUEST[$param_name]
				);
		$_REQUEST[$param_name]=charset_decode_utf_8($_REQUEST[$param_name]);
		}
	function setParams()
		{
		$this
			->addParam('text','/^[ -~\xA\xD]*$/i','')
			;
		}
	function if_not_all_parameters_are_set()
		{
		$this->ConstructLocation();
		parent::if_not_all_parameters_are_set();
		}
	/// constructor
	function HTML2BBCode()
		{
		PBasicFormSection::PBasicFormSection();
		$this->TheForm
// 				->setAtr('method','get')
			->Insert( PTextlang('Text:') )
			->Insert(
				TextArea('text',$this->getParam('text'))
					->setAtr('id','textContent')
				)
			->Insert( new PInput("submit",lang("Translate!"),"") )
			;
		}
	function	Chapter2Title()
		{
		return PTextlang('Translation:');
		}
	function	Chapter2()
		{
		if( !$this->wasParamSet('text')) return null;
		//BBCode tag markers replaced with equivalent
		return TextArea('',BBCode::HTML2BBCode($this->getParam('text')));
		}
	}
?>